package cn.hesion.leetcode;
/**
 * ClassName: TwoCitySchedCost <br/>
 * Description: <br/>
 * date: 2022/6/4 5:48<br/>
 *
 * @author Hesion<br />
 * @version
 * @since JDK 1.8
 */

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 1029. 两地调度
 *
 * @author: hesion
 * @create: 2022-06-04 05:48
 **/
public class TwoCitySchedCost {
    public  List<List<Integer>> arrToList(int[][] costs){
        List<List<Integer>> arrToList = new ArrayList<>();
        for (int i = 0; i < costs.length; i++) {
            List<Integer> arr = new ArrayList<>();
            for (int j = 0; j < costs[i].length; j++) {
                arr.add(costs[i][j]);
            }
            arrToList.add(arr);
        }
        return arrToList;
    }
    public int twoCitySchedCost(int[][] costs) {
        List<List<Integer>> lists = arrToList(costs);
        lists.sort((a,b)->{
            return (a.get(0) - a.get(1)) - (b.get(0)-b.get(1));
        });

        int n = costs.length /2;
        int i;
        int ret = 0;
        for (i= 0; i < n; i++){
            ret+=lists.get(i).get(0)+lists.get(i+n).get(1);
        }

        return ret;
    }

    public static void main(String[] args) {
        System.out.println(new TwoCitySchedCost().twoCitySchedCost(new int[][]{new int[]{259,770}, new int[]{448,54}, new int[]{926,667}, new int[]{184,139}, new int[]{840,118}, new int[]{577,469}}));
    }
}
